import { State } from '../enum'
import { Coordinate } from '../types'
import { Map } from './Map'

export class Food{
    coordinate!: Coordinate

    private map: Map
    constructor(map: Map){
        this.map = map
        this.generateFood()
    }
    generateFood(){
        let x = Math.floor(Math.random() * this.map.config.rows)
		let y = Math.floor(Math.random() * this.map.config.cols)
        if(this.map.array[x][y].state !== State.Empty) {
            this.generateFood()
            return
        }
		this.coordinate = { x: x, y: y}
		this.map.array[this.coordinate.x][this.coordinate.y].state = State.Food
    }
}